﻿using EventModel;
using MassTransit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ConsumeBus
{
    public class ConsumeEventHandler : IConsumer<IExamModel>
    {
        IConsumeRepository _consumeReposity;
        public ConsumeEventHandler(IConsumeRepository consumeReposity)
        {
            _consumeReposity = consumeReposity;
        }
        public async Task Consume(ConsumeContext<IExamModel> context)
        {
            var model = context.Message;
            var result = await _consumeReposity.SaveScore(model);
            if (result)
            {
                IMessage entity = new Message { id = model.id, status = 1 };
                await Startup.BusControl.Publish(entity);
            }
        }
    }
}
